<template>
	<view class="content" :style="getstyle()">
		<!-- 当设置tab-width,指定每个tab宽度时,则不使用flex布局,改用水平滑动 -->
		<me-asset-tabs v-model="tabIndex" :tabs="tabs" :fixed="true" ref="meassettabs">
		</me-asset-tabs>
		<uniSteps v-if="tabIndex==1" :options="stepslist"></uniSteps>
		<swiper style="height:100%;margin-top: 30px;"  :current="tabIndex" @change="swiperChange">
			<swiper-item v-for="(tab,i) in tabs" :key="i">
				<view v-if="i=='0'" v-for="(tab,s) in datas" :key="s">
					<view class="Item">
						<view class="item-link item-content">
							<view class="item-inner">
								<view class="item-text">
									<view>{{tab.name}}</view>						
								</view>
							</view>
							<view class="item-inner">
								<view class="item-text"  v-for="fileId in tab.fields">								
									<view v-if="fileId.widgetType=='file' && fileId.name=='产权证明'"
									 style="height: 200rpx;margin-top:80rpx !important;width: 48%;
									 margin-right: 48%;
									 float: left;">
										<view  class="redispan">{{fileId.name}}：</view>
										<view class="redspan" style="1rpx #f6f6f6 solid;">
											
											<image :src="getvalues(fileId)" class="item-icon" style="background-color: #f6f6f6;" 
											mode="" ></image>
										</view>		
									</view>
									<view v-if="fileId.widgetType=='file' && fileId.name!='产权证明'"
									 style="height: 200rpx;margin-top:80rpx !important;width: 48%;
									 float: left;">
										<view  class="redispan">{{fileId.name}}：</view>
										<view class="redspan" style="1rpx #f6f6f6 solid;">
											
											<image :src="getvalues(fileId)" class="item-icon" style="background-color: #f6f6f6;" 
											mode=""></image>
										</view>		
									</view>
								</view>
								
								<view class="item-text"  v-for="fileId in tab.fields">
									<view v-if="fileId.widgetType!='file'">
										<view  class="ispan">{{fileId.name}}：</view>
										<view class="span">{{fileId.value}}</view>	
																		
									</view>
								</view>
							</view>
							
						</view>
					</view>	
		
				</view>
				
			</swiper-item>
		</swiper>
		
	</view>
</template>

<script>
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
	import meassettabs from "@/components/me-asset-tabs/me-asset-tabs.vue";
	import uniSteps from '@/components/wangxiaohua--steps/index.vue';
	
	var self;
	export default {
		components: {
			MescrollBody,
			MescrollUni,
			meassettabs,
			uniSteps,
		},
		data() {
			return {
				height: "900px", // 需要固定swiper的高度
				tabs: [{
					name: '资产信息',
					code: ''
				}, {
					name: '操作记录',
					code: ''
				}],
				tabIndex: 0, // 当前tab的下标
				Type: 1,
				srcstring: "../../static/images/icon-paizhao.png",
				stepslist: [],
				datas: [],
				mydata:{},
				map:{},

			}
		},
		computed: {
			
		},
		onBackPress(options) {
			let homeassets= uni.getStorageSync("homeassets");
			uni.removeStorageSync("homeassets");
			if(homeassets=="1"){
				uni.setStorageSync('homebackDate', 0);
				uni.setStorageSync('setStatusIndexFunc', 0);
				uni.navigateTo({
					url: '../home/Index',
					animationType: 'slide-in-left',
					animationDuration: 400
				});
				return true;
			}
		},		
		methods: {
			getstyle(){
				if(this.tabIndex==0){
					return "background-color: #fff;height: 2300px;";
				}else{
					return "background-color: #fff;height: 100%;";
				}
			},
			innerclick(e) {
				self = this;
				if (self.newmodel.Groups[e.currentTarget.dataset.index].show == "1") {
					self.newmodel.Groups[e.currentTarget.dataset.index].show = "0";
				} else {
					self.newmodel.Groups[e.currentTarget.dataset.index].show = "1";
				}

			},
			// 轮播菜单
			swiperChange(e) {
				this.tabIndex = e.detail.current
			},

			getvalues(fileId){
				let value=JSON.parse(fileId.value);
				
				if(value==null){
					return "../../static/images/none.png";
				}else{
					let realUrl=value[0].realUrl.toString();
					realUrl=realUrl.replace(/\\/g,"/");	//通过replace更换字符

	
					///MoblieAPP/api.log('https://app.ztlib.com:9000/'+value[0].realUrl);
					return uni.getStorageSync("localurlfileurl")+realUrl;
					
				}
			}
			,
			request_tool(options){
			 // 在这里可以对请求头进行一些设置
			 let baseUrl = uni.getStorageSync("localurl"); 
			 let userInfo = uni.getStorageSync("userInfo");
			 if (userInfo) {
			 	options.data['userLevelCode'] =JSON.parse(userInfo).levelCode;
			 	options.data['loginUserId'] = JSON.parse(userInfo).id;
			 }
			 let userDept = uni.getStorageSync("userDept");
			 console.log(userDept);
			 if (userDept) {
			 	options.data['loginUserDeptLevelCode'] = userDept.levelCode;
			 	options.data['loginUserDeptId'] = userDept.id;
			 }
			 let currentRole = uni.getStorageSync("userRoles");
			  console.log(currentRole);
			 if (currentRole) {
			 	options.data['roleLevelCode'] = currentRole[0].levelCode;
			 	options.data['roleId'] = currentRole[0].id;
			 }
			 let userReadDeptIds = uni.getStorageSync("userReadDeptIds");
			 
			 if (userReadDeptIds) {
			 	options.data['deptIds'] =userReadDeptIds;
			 }
			  options.header = {
			      'Content-Type':'application/json',
			      Authorization: uni.getStorageSync("authorization")
			 }
			
			    return new Promise((resolve, reject) => {
			        uni.request({
			            url: baseUrl + options.url || '',
			            method: options.type || 'POST',
			            data: options.data || {},
			            header: options.header || {}      
			        }).then(data => {
			            let [err, res] = data;
						if(res.data.code==5001 || res.data.code==5002 ||
						res.data.code==5003 || res.data.code==5004){
							uni.removeStorageSync("LoginName");
							uni.removeStorageSync("userInfo");
							uni.removeStorageSync("authorization");
							uni.removeStorageSync("userToken")
							uni.removeStorageSync("userRoles");
							uni.removeStorageSync("userDept");
							uni.removeStorageSync("userReadDeptIds");
							uni.removeStorageSync("managePositionIds");
							uni.removeStorageSync("ASSETCODE");
							uni.navigateTo({
								url: '../login/login',
							});
						}
			            resolve(res);
			        }).catch(error => {
			            reject(error)
			        })
			    });
			}
			
	
			 
		},
		onLoad(options) {
			self=this;
			// 需要固定swiper的高度
			//this.height = uni.getSystemInfoSync().windowHeight + 'px'
			//console.log(options.Id)
			uni.removeStorageSync("CurrAssetId");
			uni.removeStorageSync("CurrdocumentDetailId");
			uni.removeStorageSync("CurrdocumentId");
			
			//uni.setStorageSync("CurrAssetId", options.Id);
			if (options.documentDetailId != undefined)
				uni.setStorageSync("CurrdocumentDetailId", options.documentDetailId);
			if (options.documentId != undefined)
				uni.setStorageSync("CurrdocumentId", options.documentId);
			if (options.documentDetailAssetId != undefined){
				uni.setStorageSync("CurrdocumentDetailAssetId", options.documentDetailAssetId);
			}
			var AssetId="";
			if(options.AssetCode!=undefined){
				uni.setStorageSync("CurrAssetCode", options.AssetCode);
				
			console.log(options);
			
				//点击查看
				var AssetCode = uni.getStorageSync("CurrAssetCode");
				
				console.log(AssetId);
				///app/v1/asset/findById/{id}			
						
						this.request_tool({
							url:'/app/v1/asset/findByAssetCode/'+AssetCode,
							type:'POST',
							data:{
							
						 }
						}).then(res => {
							
							console.log(res);
							if(res.data.code==2000){
								this.datas=res.data.data.convertData;
								AssetId=res.data.data.id;
								
								this.request_tool({
										url:'/app/v1/asset-log/pageDataByAssetId',
										type:'POST',
										data:{
										"assetId":AssetId
									 }
									}).then(res2 => {
										console.log(res2);
										if(res2.data.code==2000){
											let alldata=[];
											for (var i = 0; i < res2.data.data.records.length; i++) {
												let mydata= res2.data.data.records[i];
												
												var datarow = {
													"操作日期":mydata["convertData"]["createTime"],
													"操作人":mydata["convertData"]["createUser"],
													"单据编号":mydata["convertData"]["documentCode"],
													"操作类型":mydata["convertData"]["processTypeId"],
													"处理内容":mydata["convertData"]["processContent"],
												};
												
												alldata.push(datarow);
											}
											console.log(alldata);
											self.stepslist = alldata;
										}else{
											uni.showToast({
												icon: 'none',
												title: res2.data.msg
											});
										}
										
									}).catch(err => {
								  console.error(err);
								  
								});
							}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});
							}
							console.log(this.datas);
						}).catch(err => {
					  console.error(err);
					  
					});
					
				
			}else{
				uni.setStorageSync("CurrAssetId", options.Id);
					
				console.log(options);
				
					//点击查看
					AssetId = options.Id;
				this.request_tool({
						url:'/app/v1/asset/findById/'+AssetId,
						type:'POST',
						data:{
						
					 }
					}).then(res => {
						
						console.log(res);
						if(res.data.code==2000){
							this.datas=res.data.data.convertData;
							//AssetId=
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
						console.log(this.datas);
					}).catch(err => {
				  console.error(err);
				  
				});
				
				this.request_tool({
						url:'/app/v1/asset-log/pageDataByAssetId',
						type:'POST',
						data:{
						"assetId":AssetId
					 }
					}).then(res => {
						console.log(res);
						if(res.data.code==2000){
							let alldata=[];
							for (var i = 0; i < res.data.data.records.length; i++) {
								let mydata= res.data.data.records[i];
								
								var datarow = {
									"操作日期":mydata["convertData"]["createTime"],
									"操作人":mydata["convertData"]["createUser"],
									"单据编号":mydata["convertData"]["documentCode"],
									"操作类型":mydata["convertData"]["processTypeId"],
									"处理内容":mydata["convertData"]["processContent"],
								};
								
								alldata.push(datarow);
							}
							console.log(alldata);
							self.stepslist = alldata;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
								});
						}
						
					}).catch(err => {
				  console.error(err);
				  
				});
			}
			
			
			
			
				
			
		}
	}
</script>

<style>
	.item-icon {
		width: 100upx;
		height: 100upx;
	}
	.content {
		background-color: #edf1f4;
	}
	
	.Item {
		overflow: hidden;
		border-radius: 16rpx;
		background: #fff;
		margin-top: 10rpx;
	}
	
	.item-text .span {
		display: inline-block;
		width: 67%;
		float: right;
		word-wrap: break-word; /* 使得长单词或URL可以换行 */
		    overflow-wrap: break-word; /* 现代替代，功能同上 */
		
	}
	
	.item-text .ispan {
		font-style: normal;
		width: 30%;
		display: inline-block;
		color: #9E9CA5;
	}
	
	.item-content {
		padding-left: 0;
	}
	
	.item-title .ispan {
		font-size: 30rpx;
		width: auto;
		height: auto;
	}
	
	.item-title {
		font-size: 40rpx;
		color: #454545;
		width: 100%;
	}
	
	.item-title-row {
		background-image: none;
		padding-right: 0px;
	}
	
	.item-link .item-inner {
		padding-right: 0;
	}
	.item-text {
		font-size: 30rpx;
		color: #454545;
		margin: 20rpx 0;
		padding-left: 20rpx;
		line-height: 1.2;
	}
	
	.item-text .redispan {
		font-style: normal;
		width: 50%;
		display: inline-block;
	}
	
	.item-text .redspan {
		display: inline-block;
		width: 50%;
		float: right;
		
	}
</style>
